<?php 
class Mplaylist extends CI_Model {
    public  function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function getPlaylist($id) {
    	$result=$this->db->query("SELECT userplaylist.idPlaylist,userplaylist.strNamePList,userplaylist.strDateCreate,userplaylist.rating,userplaylist.strPListImage,userplaylist.strComment,users.strName,theme.idTheme,theme.strTheme,genre.idGenre,genre.strGenre
    		FROM userplaylist 
    		LEFT JOIN playlistsong ON CONVERT(userplaylist.idPlaylist USING utf8) =CONVERT(playlistsong.idPlaylist USING utf8)
			LEFT JOIN users ON CONVERT(userplaylist.idUser USING utf8)=CONVERT(users.idUser USING utf8) 
			LEFT JOIN theme ON CONVERT(userplaylist.idTheme USING utf8)=CONVERT(theme.idTheme USING utf8)
			LEFT JOIN genre ON CONVERT(userplaylist.idGenre USING utf8)=CONVERT(genre.idGenre USING utf8)
			WHERE userplaylist.idPlaylist LIKE '$id'
			
		");
		return $result->result_array();
    }
    public function getSongPlaylist($id) {
    	$result=$this->db->query("SELECT song.idSong,song.strExtraArtist,song.strPath,artist.strArtist ,song.strFileName
    		FROM song  
    		LEFT JOIN playlistsong ON CONVERT(song.idSong USING utf8) =CONVERT(playlistsong.idSong USING utf8)
			LEFT JOIN artist ON CONVERT(song.idArtist USING utf8) =CONVERT(artist.idArtist USING utf8)
			WHERE playlistsong.idPlaylist LIKE '$id'
    		ORDER BY playlistsong.iPosition DESC
    		");
    	return $result->result_array();

    }
    public function updateRating($id,$value) {
    	$this->db->query("UPDATE userplaylist 
								 SET rating=$value
								 WHERE idPlaylist='$id'");
    }

} 

?>